package com.sharejoys.revealanimationdemo;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.LinearInterpolator;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.btn1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Animator animator = ViewAnimationUtils.createCircularReveal(v, 2, 2, 0, v.getWidth());
                animator.setDuration(500);
                animator.setInterpolator(new AccelerateInterpolator());
                animator.start();
            }
        });
        findViewById(R.id.btn2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int width = v.getWidth();
                int height = v.getHeight();
                Animator animator = ViewAnimationUtils.createCircularReveal(v, width / 2, height / 2, 0, Math.max(width, height));
                animator.setDuration(1000);
                animator.setInterpolator(new LinearInterpolator());
                animator.start();
//                lowVersion(v);
            }
        });
    }

    private View view;

    private void lowVersion(final View view) {
        ValueAnimator valueAnimator = ValueAnimator.ofFloat(1000);
        valueAnimator.setDuration(400);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float animatedFraction = animation.getAnimatedFraction();
                view.setScaleX(animatedFraction);
                view.setScaleY(animatedFraction);
            }
        });
        valueAnimator.setInterpolator(new LinearInterpolator());
        valueAnimator.start();
    }
}
